import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
# coding=utf-8
import warnings
warnings.filterwarnings("ignore")

df = pd.read_csv("demo.csv", encoding='gb18030')
X = df[['年']]
Y = df[['人口']]

model = LinearRegression()
model.fit(X, Y)
x = int(input("请输入年份（如2050）: "))
y = model.predict([[x]])
print("中国人口预计是：%.2f亿"%(y/10000))

#plt.figure('Linear Regression', facecolor='lightgray')
plt.title('Linear Regression', fontsize=20)
plt.xlabel('Year', fontsize=14)
plt.ylabel('Population', fontsize=14)
#plt.tick_params(labelsize=10)
#plt.grid(linestyle=':')
plt.scatter(X, Y, c='dodgerblue', alpha=0.75, s=60, label='Sample')
plt.plot(X, model.predict(X),  c='orangered', label='Regression')
plt.legend()
plt.show()
